home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 440_01 / examples / !cursor.asm next >
Encoding:
Assembly Source File  |  1993-07-16  |  16.6 KB  |  373 lines

  1. ;library of text mode cursor routines
  2. ;independently authored by George Vanous
  3.  
  4. PARMA   equ     6               ;necessary for far procedures
  5. PARMB   equ     PARMA + 2
  6. PARMC   equ     PARMB + 2
  7. PARMD   equ     PARMC + 2
  8.  
  9. TCUR    equ     -1              ;text cursor identification
  10. MCUR    equ     -2              ;mouse cursor identification
  11. ACUR    equ     -3              ;memory cursor identification
  12. GRAFIX  equ     10              ;identification for 640x480x16 graphics mode
  13.  
  14. KEYBEEP MACRO
  15.         push ax
  16.         push dx
  17.         mov  ah,02
  18.         mov  dl,07
  19.         int  21h
  20.         pop  dx
  21.         pop  ax
  22. ENDM
  23.  
  24. extrn  TXTOFF_A:word            ;offset of active text page
  25. extrn  TXTOFF_V:word            ;offset of visual text page
  26.  
  27. public CUROFF                   ;offset of cursor on active text page
  28. public CUROFF1                  ;offset of cursor on text page 1
  29. public CUROFF2                  ;offset of cursor on text page 2
  30. public CUROFF3                  ;offset of cursor on text page 3
  31. public CUROFF4                  ;offset of cursor on text page 4
  32. public CUROFF5                  ;offset of cursor on text page 5
  33. public CUROFF6                  ;offset of cursor on text page 6
  34. public CUROFF7                  ;offset of cursor on text page 7
  35. public CUROFF8                  ;offset of cursor on text page 8
  36. public CURSHP                   ;cursor shape on active text page
  37. public CUROFFo            ;offsets of CUROFF?
  38. public CURSHP1                  ;cursor shape on text page 1
  39. public CURSHP2                  ;cursor shape on text page 2
  40. public CURSHP3                  ;cursor shape on text page 3
  41. public CURSHP4                  ;cursor shape on text page 4
  42. public CURSHP5                  ;cursor shape on text page 5
  43. public CURSHP6                  ;cursor shape on text page 6
  44. public CURSHP7                  ;cursor shape on text page 7
  45. public CURSHP8                  ;cursor shape on text page 8
  46. public CURSHPo            ;offsets of CURSHP?
  47.  
  48. public __cur_get                ;01
  49. public __cur_getx               ;02
  50. public __cur_gety               ;03
  51. public __cur_off                ;04
  52. public __cur_on                 ;05
  53. public __cur_set                ;06
  54. public __cur_setx               ;07
  55. public __cur_sety               ;08
  56. public __cur_shapeget           ;09
  57. public __cur_shapeset           ;10
  58.  
  59. ;*****************************************************************************
  60. _TEXT   segment byte public 'CODE'
  61.  
  62.         assume  cs:_TEXT,ds:_DATA
  63.  
  64. ;-----------------------------------------------------------------------------
  65. __cur_get proc  far             ;MODIFIES AX BX CX
  66. ; void _cur_get(byte *x, byte *y);
  67.  
  68.         push bp                 ;
  69.         mov  bp,sp              ;
  70.         push ds                 ;
  71.          mov  ax,seg _DATA      ;
  72.          mov  ds,ax             ;DS = segment of our data
  73.          mov  bx,CUROFF         ;
  74.          mov  ax,[bx]           ;AX = offset of cursor
  75.          sub  ax,TXTOFF_A       ;AX = offset of cursor on active text page
  76.          mov  cl,050h           ;CL = 80 (byte-length of one text row)
  77.          div  cl                ;AH = cursor abscissa   AL = cursor ordinate
  78.          mov  bx,[bp+PARMC]     ;BX = offset of cursor ordinate pointer
  79.          or   bx,bx             ;offset = NULL (the first paramater is "*xy")?
  80.          jz   skip01a           ;jump if so
  81.          mov  ds,[bp+PARMD]     ;DS:BX = segment:offset of cursor ordinate ptr
  82.          mov  [bx],al           ;store cursor ordinate
  83.          lds  bx,[bp+PARMA]     ;DS:BX = segment:offset of cursor abscissa ptr
  84.          mov  [bx],ah           ;store cursor abscissa
  85.          jmp  short out01       ;
  86. skip01a: lds  bx,[bp+PARMA]     ;DS:BX = seg:off of cur. abscissa/ordinate ptr
  87.          xchg al,ah             ;AH = cursor ordinate   AL = cursor abscissa
  88.          mov  [bx],ax           ;store cursor abscissa then cursor ordinate
  89. out01:  pop  ds                 ;
  90.         pop  bp                 ;
  91.         ret                     ;
  92.  
  93. __cur_get endp
  94.  
  95. ;-----------------------------------------------------------------------------
  96. __cur_getx proc far             ;MODIFIES AX BX
  97. ; byte _cur_getx(void);
  98.  
  99.         push ds                 ;
  100.          mov  ax,seg _DATA      ;
  101.          mov  ds,ax             ;DS = segment of our data
  102.          mov  bx,CUROFF         ;
  103.          mov  ax,[bx]           ;AX = offset of cursor
  104.          sub  ax,TXTOFF_A       ;AX = offset of cursor on active text page
  105.          mov  bl,050h           ;BL = 80 (byte-length of one text row)
  106.          div  bl                ;AX = AX / BL (cursor address / 160)
  107.          mov  al,ah             ;AL = cursor abscissa
  108.          xor  ah,ah             ;AX = cursor abscissa
  109.         pop  ds                 ;
  110.         ret                     ;return cursor abscissa
  111.  
  112. __cur_getx endp
  113.  
  114. ;-----------------------------------------------------------------------------
  115. __cur_gety proc far             ;MODIFIES AX BX
  116. ; byte _cur_gety(void);
  117.  
  118.         push ds                 ;
  119.          mov  ax,seg _DATA      ;
  120.          mov  ds,ax             ;DS = segment of our data
  121.          mov  bx,CUROFF         ;
  122.          mov  ax,[bx]           ;AX = offset of cursor
  123.          sub  ax,TXTOFF_A       ;AX = offset of cursor on active text page
  124.          mov  bl,050h           ;BL = 80 (byte-length of one text row)
  125.          div  bl                ;AX = AX / BL (cursor address / 160)
  126.          xor  ah,ah             ;AH = cursor ordinate
  127.         pop  ds                 ;
  128.         ret                     ;return cursor ordinate
  129.  
  130. __cur_gety endp
  131.  
  132. ;-----------------------------------------------------------------------------
  133. __cur_off proc  far             ;MODIFIES AX DX
  134. ; void _cur_off(void);
  135.  
  136.          mov  al,0Ah            ;address Cursor Start Register
  137.          mov  dx,03D4h          ;DX = 03D4h, address of CRT Controller reg.
  138.          out  dx,al             ;set Cursor Start Register active
  139.          in   ax,dx             ;AH = value of Cursor Start Register
  140.          or   ah,00100000b      ;set Cursor On/Off (COO) to 1 (off)
  141.          out  dx,ax             ;turn off the cursor
  142.         ret                     ;
  143.  
  144. __cur_off endp
  145.  
  146. ;-----------------------------------------------------------------------------
  147. __cur_on proc   far             ;MODIFIES AX DX
  148. ; void _cur_on(void);
  149.  
  150.          mov  al,0Ah            ;address Cursor Start Register
  151.          mov  dx,03D4h          ;DX = 03D4h, address of CRT Controller reg.
  152.          out  dx,al             ;set Cursor Start Register active
  153.          in   ax,dx             ;AH = value of Cursor Start Register
  154.          and  ah,11011111b      ;set Cursor On/Off (COO) to 0 (on)
  155.          out  dx,ax             ;turn on the cursor
  156.         ret                     ;
  157.  
  158. __cur_on endp
  159.  
  160. ;-----------------------------------------------------------------------------
  161. __cur_set proc  far             ;MODIFIES AX BX CX DX
  162. ; byte _cur_set(byte x, byte y);
  163.  
  164.         push bp                 ;
  165.         mov  bp,sp              ;
  166.         push ds                 ;
  167.          mov  ax,seg _DATA      ;
  168.          mov  ds,ax             ;DS = segment of our data
  169.          mov  al,[bp+PARMA]     ;AL = cursor abscissa
  170.          xor  ah,ah             ;AX = cursor abscissa
  171.          mov  cl,[bp+PARMB]     ;CL = cursor ordinate
  172.          mov  ch,ah             ;CX = cursor ordinate
  173.          push ax                ;needed for "__cursetx" and "__cursety"
  174. jump06a: shl  cx,1              ;ordinate * 2
  175.          shl  cx,1              ;ordinate * 4
  176.          shl  cx,1              ;ordinate * 8
  177.          shl  cx,1              ;ordinate * 16
  178.          mov  bx,cx             ;BX = ordinate * 16
  179.          shl  cx,1              ;ordinate * 32
  180.          shl  cx,1              ;ordinate * 64
  181.          add  cx,bx             ;ordinate*64 + ordinate*16 = ordinate*80
  182.          add  cx,ax             ;DI = ordinate*80 + abscissa
  183.          mov  ax,TXTOFF_A       ;AX = offset of active text page
  184.          add  cx,ax             ;position in active text page
  185.          mov  bx,CUROFF         ;
  186.          mov  [bx],cx           ;store offset of cursor on active text page
  187.          cmp  ax,TXTOFF_V       ;active page offset = video page offset?
  188.          jne  out06             ;jump if not so
  189.          mov  al,0Eh            ;address Cursor Location High register
  190.          mov  ah,ch             ;AH = new cursor position high
  191.          mov  dx,03D4h          ;DX = 03D4h, address of CRT Controller reg.
  192.          out  dx,ax             ;set Cursor Location High
  193.          inc  al                ;AL = 0Fh, address Cursor Location Low reg.
  194.          mov  ah,cl             ;AH = new cursor position low
  195.          out  dx,ax             ;set Cursor Location Low
  196. out06:  pop  ax                 ;AX = cursor abscissa or cursor ordinate
  197.         pop  ds                 ;
  198.         pop  bp                 ;
  199.         ret                     ;return cursor abscissa or cursor ordinate
  200.  
  201. __cur_set endp
  202.  
  203. ;-----------------------------------------------------------------------------
  204. __cur_setx proc far             ;MODIFIES AX BX DX
  205. ; byte _cur_setx(byte x);
  206.  
  207.         push bp                 ;
  208.         mov  bp,sp              ;
  209.         push ds                 ;
  210.          mov  ax,seg _DATA      ;
  211.          mov  ds,ax             ;DS = segment of our data
  212.          mov  bx,CUROFF         ;
  213.          mov  ax,[bx]           ;AX = offset of cursor
  214.          sub  ax,TXTOFF_A       ;AX = offset of cursor on active text page
  215.          mov  bl,050h           ;BL = 80 (byte-length of one text row)
  216.          div  bl                ;AX = AX / BL (cursor address / 160)
  217.          xor  ah,ah             ;AX = cursor ordinate
  218.          push ax                ;save ordinate for return value
  219.          mov  cx,ax             ;CX = cursor ordinate
  220.          mov  al,[bp+PARMA]     ;AX = desired cursor abscissa
  221.          jmp  short jump06a     ;
  222.  
  223. __cur_setx endp
  224.  
  225. ;-----------------------------------------------------------------------------
  226. __cur_sety proc far             ;MODIFIES AX BX DX
  227. ; byte _cur_sety(byte y);
  228.  
  229.         push bp                 ;
  230.         mov  bp,sp              ;
  231.         push ds                 ;
  232.          mov  ax,seg _DATA      ;
  233.          mov  ds,ax             ;DS = segment of our data
  234.          mov  bx,CUROFF         ;
  235.          mov  ax,[bx]           ;AX = offset of cursor
  236.          sub  ax,TXTOFF_A       ;AX = offset of cursor on active text page
  237.          mov  bl,050h           ;BL = 80 (byte-length of one text row)
  238.          div  bl                ;AX = AX / BL (cursor address / 160)
  239.          mov  al,ah             ;AL = cursor abscissa
  240.          xor  ah,ah             ;AX = cursor abscissa
  241.          push ax                ;save abscissa for return value
  242.          mov  cl,[bp+PARMA]     ;CL = cursor ordinate
  243.          mov  ch,ah             ;CX = cursor ordinate
  244.          jmp  short jump06a     ;
  245.  
  246. __cur_sety endp
  247.  
  248. ;-----------------------------------------------------------------------------
  249. __cur_shapeget proc far         ;MODIFIES AX BX CX DX
  250. ; void _cur_shapeget(byte *start, byte *end);
  251.  
  252.         push bp                 ;
  253.         mov  bp,sp              ;
  254.         push ds                 ;
  255.          mov  ax,seg _DATA      ;
  256.          mov  ds,ax             ;DS = segment of our data
  257.          mov  bx,CURSHP         ;
  258.          mov  dx,[bx]           ;DH = ending scanline   DL = starting scanline
  259.          mov  bx,[bp+PARMC]     ;BX = offSET of ending scan line pointer
  260.          or   bx,bx             ;offset of ending scan line pointer = NULL?
  261.          jz   skip09a           ;jump if so
  262.          mov  ds,[bp+PARMD]     ;DS:BX = seg:off of ending scan line pointer
  263.          mov  [bx],dh           ;store ending scan line of cursor
  264.          lds  bx,[bp+PARMA]     ;DS:BX = seg:off of starting scan line pointer
  265.          mov  [bx],dl           ;store starting scan line of cursor
  266.          jmp  short out09       ;
  267. skip09a: lds  bx,[bp+PARMA]     ;DS:BX = seg:off of start/end scan line ptr
  268.          mov  [bx],dh           ;store starting scan line of cursor
  269.          mov  [bx+01h],dl       ;store ending scan line of cursor
  270. out09:  pop  ds                 ;
  271.         pop  bp                 ;
  272.         ret                     ;
  273.  
  274. __cur_shapeget endp
  275.  
  276. ;-----------------------------------------------------------------------------
  277. __cur_shapeset proc far         ;MODIFIES AX BX CX DX
  278. ; void _cur_shapeset(byte start, byte end);
  279.  
  280.         push bp                 ;
  281.         mov  bp,sp              ;
  282.         push ds                 ;
  283.          mov  ax,seg _DATA      ;
  284.          mov  ds,ax             ;DS = segment of our data
  285.          mov  cl,[bp+PARMA]     ;CL = new starting scan line of cursor
  286.          cmp  cl,0FFh           ;modify the starting scan line?
  287.          je   skip10a           ;jump if not so
  288.          mov  [bx],cl           ;store new starting scan line of cursor
  289. skip10a: mov  ch,[bp+PARMB]     ;CH = new ending scan line of cursor
  290.          cmp  cx,0FFFFh         ;do not modify starting and ending scan line?
  291.          je   out10a            ;jump if so
  292.          mov  [bx+01h],ch       ;store new ending scan line of cursor
  293. skip10b: mov  ax,TXTOFF_A       ;AX = offset of active text page
  294.          cmp  ax,TXTOFF_V       ;active page offset = video page offset?
  295.          jne  out10             ;jump if not so
  296.  
  297.          mov  al,0Ah            ;address Cursor Start Register
  298.          mov  dx,03D4h          ;DX = 03D4h, address of CRT Controller reg.
  299.          cmp  cl,0FFh           ;modify the starting scan line?
  300.          je   skip10c           ;jump if not so
  301.          out  dx,al             ;set Cursor Start Register active
  302.          in   ax,dx             ;AH = value of Cursor Start Register
  303.          and  ah,11100000b      ;mask out current starting scan line of cursor
  304.          or   ah,cl             ;input new starting scan line of cursor
  305.          out  dx,ax             ;set Cursor Start Register
  306. skip10c: inc  al                ;AL = 0Bh, address Cursor End Register
  307.          cmp  ch,0FFh           ;modify the ending scan line?
  308.          je   out10             ;jump if not so
  309.          out  dx,al             ;set Cursor End Register active
  310.          in   ax,dx             ;AH = value of Cursor End Register
  311.          and  ah,11100000b      ;mask out current ending scan line of cursor
  312.          or   ah,ch             ;input new ending scan line of cursor
  313.          out  dx,ax             ;set Cursor End Register
  314. out10:  pop  ds                 ;
  315.         pop  bp                 ;
  316.         ret                     ;
  317. out10a: KEYBEEP                 ;beep to signify error
  318.          jmp  short out10       ;
  319.  
  320. __cur_shapeset endp
  321.  
  322. ;-----------------------------------------------------------------------------
  323. _TEXT   ends                    ;end of code segment
  324.  
  325. ;*****************************************************************************
  326. _DATA   segment byte public 'DATA'
  327.  
  328. ;-----------------------------------------------------------------------------
  329.  
  330. ;all offsets are relative to B000:8000
  331. CUROFF    dw   CUROFF1        ;offset of cursor on active text page
  332. CUROFF1 dw   0000h        ;offset of cursor on text page 1
  333. CUROFF2 dw   0FA0h        ;offset of cursor on text page 2
  334. CUROFF3 dw   1F40h        ;offset of cursor on text page 3
  335. CUROFF4 dw   2EE0h        ;offset of cursor on text page 4
  336. CUROFF5 dw   3E80h        ;offset of cursor on text page 5
  337. CUROFF6 dw   4E20h        ;offset of cursor on text page 6
  338. CUROFF7 dw   5DC0h        ;offset of cursor on text page 7
  339. CUROFF8 dw   6D60h        ;offset of cursor on text page 8
  340. CUROFFo dw   CUROFF1        ;offsets of CUROFF?
  341.     dw   CUROFF2        ;
  342.     dw   CUROFF3        ;
  343.     dw   CUROFF4        ;
  344.     dw   CUROFF5        ;
  345.     dw   CUROFF6        ;
  346.     dw   CUROFF7        ;
  347.     dw   CUROFF8        ;
  348.  
  349. CURSHP  dw   CURSHP1            ;cursor shape on active text page
  350. CURSHP1 dw   0D0Eh              ;cursor shape on text page 1
  351.   ; [cursor starting scan line] [cursor ending scan line] (back-words storage)
  352. CURSHP2 dw   0D0Eh              ;cursor shape on text page 2
  353. CURSHP3 dw   0D0Eh              ;cursor shape on text page 3
  354. CURSHP4 dw   0D0Eh              ;cursor shape on text page 4
  355. CURSHP5 dw   0D0Eh              ;cursor shape on text page 5
  356. CURSHP6 dw   0D0Eh              ;cursor shape on text page 6
  357. CURSHP7 dw   0D0Eh              ;cursor shape on text page 7
  358. CURSHP8 dw   0D0Eh              ;cursor shape on text page 8
  359. CURSHPo dw   CURSHP1        ;offsets of CURSHP?
  360.     dw   CURSHP2        ;
  361.     dw   CURSHP3        ;
  362.     dw   CURSHP4        ;
  363.     dw   CURSHP5        ;
  364.     dw   CURSHP6        ;
  365.     dw   CURSHP7        ;
  366.     dw   CURSHP8        ;
  367.  
  368. ;-----------------------------------------------------------------------------
  369. _DATA   ends
  370.  
  371. ;*****************************************************************************
  372.         end                     ;end of assembly
  373.